﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OfficeBusiness.Model;
using System.Windows;

namespace OfficeBusiness.ViewModel
{
    public class BaseViewModel : ViewModelBase
    {
        private IBusinessModel businessModel;
        private DepartmentViewModel departmentViewModel;
        private EmployeeViewModel employeeViewModel;
        private SelectViewModel selectViewModel;
        private WorksViewModel worksViewModel;
        private ProjectViewModel projectViewModel;

        private Visibility departmentVisibility;
        private Visibility employeesVisibility;
        private Visibility projectsVisibility = Visibility.Collapsed;
        private Visibility worksVisibility = Visibility.Collapsed;

        public BaseViewModel()
        {
            this.businessModel = new BusinessModel();
            this.businessModel.DepartmentSelectedEvent += new EventHandler(DepartmentSelected);
            this.businessModel.EmployeeSelectedEvent += new EventHandler(EmployeeSelected);
            this.businessModel.ProjectsSelectedEvent += new EventHandler(ProjectSelected);
            this.businessModel.WorksSelectedEvent += new EventHandler(WorkSelected);
        }

        public DepartmentViewModel DepartmentViewModel
        {
            get
            {
                if (this.departmentViewModel == null)
                {
                    this.departmentViewModel = new DepartmentViewModel(this.businessModel);
                }

                return this.departmentViewModel;
            }
        }

        public EmployeeViewModel EmployeeViewModel
        {
            get
            {
                if (this.employeeViewModel == null)
                {
                    this.employeeViewModel = new EmployeeViewModel(this.businessModel);
                }

                return this.employeeViewModel;
            }
        }

        public SelectViewModel SelectViewModel
        {
            get
            {
                if (this.selectViewModel == null)
                {
                    this.selectViewModel = new SelectViewModel(this.businessModel);
                }

                return this.selectViewModel;
            }
        }

        public WorksViewModel WorksViewModel
        {
            get
            {
                if (this.worksViewModel == null)
                {
                    this.worksViewModel = new WorksViewModel(this.businessModel);
                }

                return this.worksViewModel;
            }
        }

        public ProjectViewModel ProjectViewModel
        {
            get
            {
                if (this.projectViewModel == null)
                {
                    this.projectViewModel = new ProjectViewModel(this.businessModel);
                }

                return this.projectViewModel;
            }
        }

        public Visibility DepartmentVisibility
        {
            get
            {
                return this.departmentVisibility;
            }

            set
            {
                this.departmentVisibility = value;
                OnPropertyChanged("DepartmentVisibility");
            }
        }

        public Visibility EmployeesVisibility
        {
            get
            {
                return this.employeesVisibility;
            }

            set
            {
                this.employeesVisibility = value;
                OnPropertyChanged("EmployeesVisibility");
            }
        }

        public Visibility ProjectsVisibility
        {
            get
            {
                return this.projectsVisibility;
            }

            set
            {
                this.projectsVisibility = value;
                OnPropertyChanged("ProjectsVisibility");
            }
        }

        public Visibility WorksVisibility
        {
            get
            {
                return this.worksVisibility;
            }

            set
            {
                this.worksVisibility = value;
                OnPropertyChanged("WorksVisibility");
            }
        }

        private void WorkSelected(object worksVis, EventArgs e)
        {
            if (worksVis != null)
            {
                if ((Visibility)worksVis == Visibility.Collapsed)
                {
                    this.EmployeesVisibility = Visibility.Collapsed;
                    this.WorksVisibility = Visibility.Visible;
                }
                else if ((Visibility)worksVis == Visibility.Visible)
                {
                    this.EmployeesVisibility = Visibility.Visible;
                    this.WorksVisibility = Visibility.Collapsed;
                }
            }
        }

        private void ProjectSelected(object projVis, EventArgs e)
        {
            if (projVis != null)
            {
                if ((Visibility)projVis == Visibility.Collapsed)
                {
                    this.DepartmentVisibility = Visibility.Collapsed;
                    this.ProjectsVisibility = Visibility.Visible;
                }
                else if ((Visibility)projVis == Visibility.Visible)
                {
                    this.DepartmentVisibility = Visibility.Visible;
                    this.ProjectsVisibility = Visibility.Collapsed;
                }
            }
        }

        private void DepartmentSelected(object deptVis, EventArgs e)
        {
            if (deptVis != null)
            {
                if ((Visibility)deptVis == Visibility.Collapsed)
                {
                    this.ProjectsVisibility = Visibility.Visible;
                    this.DepartmentVisibility = Visibility.Collapsed;
                }
                else if ((Visibility)deptVis == Visibility.Visible)
                {
                    this.ProjectsVisibility = Visibility.Collapsed;
                    this.DepartmentVisibility = Visibility.Visible;
                }
            }
        }

        private void EmployeeSelected(object empVis, EventArgs e)
        {
            if (empVis != null)
            {
                if ((Visibility)empVis == Visibility.Collapsed)
                {
                    this.WorksVisibility = Visibility.Visible;
                    this.EmployeesVisibility = Visibility.Collapsed;
                }
                else if ((Visibility)empVis == Visibility.Visible)
                {
                    this.WorksVisibility = Visibility.Collapsed;
                    this.EmployeesVisibility = Visibility.Visible;
                }
            }
        }
    }
}
